package com.mmp.main.servlet;

import java.io.IOException;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mmp.common.servlet.BasicServlet;
import com.mmp.main.entity.Site;
import com.mmp.main.util.WebUtil;

@WebServlet(urlPatterns = { "/ViewDevicesUnderMaintenanceAlias", "/ViewDevicesNotInContractAlias",
		"/ViewDevicesFromOtherSitesAlias", "/ViewDevicesTransferredAlias", "/ViewDevicesScrappedAlias",
		"/ViewPPMNotHappenedVisitsAlias", "/ViewOpenedJobOrdersAlias", "/ViewLateJobOrdersAlias" })
public class ChooseReportTypePreference extends BasicServlet {

	private static HashMap<String, String> destinations;

	static {
		destinations = new HashMap<String, String>();

		destinations.put("ViewDevicesUnderMaintenanceAlias", "ViewDevicesUnderMaintenance");
		destinations.put("ViewDevicesNotInContractAlias", "ViewDevicesNotInContract");
		destinations.put("ViewDevicesFromOtherSitesAlias", "ViewDevicesFromOtherSites");
		destinations.put("ViewDevicesTransferredAlias", "ViewDevicesTransferred");
		destinations.put("ViewDevicesScrappedAlias", "ViewDevicesScrapped");
		destinations.put("ViewPPMNotHappenedVisitsAlias", "ViewPPMNotHappenedVisits");
		destinations.put("ViewOpenedJobOrdersAlias", "ViewOpenedJobOrders");
		destinations.put("ViewLateJobOrdersAlias", "ViewLateJobOrders");

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
			IOException {

		String dest = destinations.get(WebUtil.getRequestUri(request));

		Site currentSite = getSessionUser(request).getSite();

		if (currentSite.getContainsSeveralLocations()) {
			request.setAttribute("formAction", dest);
			forward(request, response, "ChooseReportTypePreferenceForm.jsp");
		} else {
			basicForward(request, response, dest);
		}
	}

}
